//引入对应模块
import Vue from 'vue'
import VueRouter from 'vue-router'

//注册路由模块
Vue.use(VueRouter)

//原型上修改 push/replace 方法
const originPush = VueRouter.prototype.push
const originReplace = VueRouter.prototype.push

//修改VueRouter上的push方法，用于解决重复跳转时报错的问题
VueRouter.prototype.push = function(location,okCallBack,errCallBack){
    if(okCallBack === undefined && errCallBack === undefined){
        originPush.call(this,location).catch(()=>{})
    }else{
        originPush.call(this,location,okCallBack,errCallBack)
    }
}

//修改VueRouter上的replace方法，用于解决重复跳转的问题
VueRouter.prototype.replace = function(location,okCallBack,errCallBack){
    if(okCallBack === undefined && errCallBack === undefined){
        originReplace.call(this,location).catch(()=>{})
    }else{
        originReplace.call(this,location,okCallBack,errCallBack)
    }
}

// 引入对应组件
import Home from '../pages/Home'
import Search from '../pages/Search'
import Login from '../pages/Login'
import Register from '../pages/Register'

//设置路由信息
const router = new VueRouter({
    mode:'history',
    routes:[
        {
            name:'Home',
            path:'/home',
            component:Home,
            meta:{
                isHiddenNav:true
            }
        },
        {
            name:'Search',
            path:'/search',
            component:Search
        },
        {
            name:'Login',
            path:'/login',
            component:Login,
            meta:{
                isHiddenFooter:true
            }
        },
        {
            name:'Register',
            path:'/register',
            component:Register,
            meta:{
                isHiddenFooter: true
            }
        },
        {
            path:'/',
            redirect:'/home'
        }
    ]
})

export default router